package com.gking.centerSystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gking.centerSystem.entity.Routes;
import com.gking.centerSystem.entity.Sort;
import com.gking.centerSystem.entity.SystemInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoutesMapper extends BaseMapper<Routes> {


    /**
     * 获取路由列表
     *
     * @param page    分页信息
     * @param sortIds 分类id列表
     * @return
     */
    @Select("<script>" +
            "SELECT DISTINCT routes.* " +
            "FROM sy_routes routes " +
            "JOIN sy_sort sort ON sort.id = routes.sortId " +
            "JOIN sy_root_system rootSystem ON rootSystem.systemCode = sort.systemCode " +
            "WHERE rootSystem.enable = 0 AND rootSystem.isDelete = 0 " +
            "AND sort.isDelete = 0 " +

            "<if test='sortIds != null and !sortIds.isEmpty()'>" +
            " AND routes.sortId IN " +
            " <foreach item='sortId' collection='sortIds' open='(' separator=',' close=')'>" +
            "   #{sortId}" +
            " </foreach>" +
            "</if> " +

            "ORDER BY routes.createTime DESC  " +
            "</script>")
    Page<Routes> getRoutesListBySort(Page<Routes> page,
                               @Param("sortIds") List<String> sortIds);

    /**
     * 获取路由列表
     *
     * @param page 分页信息
     * @return
     */
    @Select("<script>" +
            "SELECT DISTINCT routes.* " +
            "FROM sy_routes routes " +
            "JOIN sy_sort sort ON sort.id = routes.sortId " +
            "JOIN sy_root_system rootSystem ON rootSystem.systemCode = sort.systemCode " +
            "WHERE rootSystem.enable = 0 AND rootSystem.isDelete = 0 " +
            "AND sort.isDelete = 0 " +
            "ORDER BY routes.createTime DESC  " +
            "</script>")
    Page<Routes> getRoutesList(Page<Routes> page);


}
